module.exports = function ($scope, $modal, $resource, getDate, toaster) {

    $scope.search = function () {
        $scope.searchform.tour_date = getDate($scope.searchform.tour_date);
        $scope.total.booked = 0;
        $scope.total.self = 0;
        $scope.total.tour = 0;
        $resource('/api/as/ggc/order/getOrderAccount2List', {}, {}).save($scope.searchform, function (res) {
            if (res.errcode === 0) {
                $scope.result_list = res.data;
                angular.forEach(res.data, function (item) {
                    $scope.total.booked += item.booked;
                    $scope.total.self += item.self;
                    $scope.total.tour += item.tour;
                });
            } else {
                toaster.error({ title: '', body: '统计失败, 请重试' });
            }
        });
    }

    init();
    function init() {
        $scope.searchform = {
            'usedate': 0,
            'tour_date': getDate(new Date()),
            'opened': false
        };
        $scope.total = {};
        $scope.search();
        $resource('/api/as/ggc/activity/forSearchList', {}, {}).save({}, function (res) {
            if (res.errcode === 0) {
                $scope.activity_list = res.data;
                $scope.activity_list.unshift({ 'title': '全部', 'activity_id': undefined });
            } else {
                toaster.error({ title: '', body: '查询公益游列表失败' });
            }
        });
    }

    $scope.info = function (obj) {
        if (!obj.addressList.length) {
            toaster.error({ title: '', body: '此机构当天所有地点都没有人报名！' });
            return false;
        }
        var modalInstance = $modal.open({
            template: require('../views/tourAddressList.html'),
            controller: 'tourAddressList',
            size: 'lg',
            resolve: {
                item: function () {
                    return obj;
                }
            }
        });
        modalInstance.result.then(function (result) {
            $scope.order_info = result;
        });
    }

    //打开日历空间,选择时间
    $scope.dateOpen = function ($event, item) {
        $event.preventDefault();
        $event.stopPropagation();
        item.opened = true;
    };

};